// This file contains notification-related API functions
import type { 
  MarkAsReadData, MarkAsReadResponses,
  SendTestMessageData, SendTestMessageResponses,
  BatchMarkAsReadData, BatchMarkAsReadResponses,
  GetMessagesData, GetMessagesResponses,
  GetUnreadCountData, GetUnreadCountResponses,
  GetUnreadCountByTypeData, GetUnreadCountByTypeResponses,
  DeleteMessageData, DeleteMessageResponses
} from './notificationTypes';
import { client as _heyApiClient } from '../../api/client.gen';
import type { Options } from '../common/apiTypes';

/**
 * 标记消息已读
 * 将指定消息标记为已读状态
 */
export const markAsRead = <ThrowOnError extends boolean = false>(options: Options<MarkAsReadData, ThrowOnError>) => {
    return (options.client ?? _heyApiClient).post<MarkAsReadResponses, unknown, ThrowOnError>({
        url: '/api/notifications/{messageId}/read',
        ...options
    });
};

/**
 * 发送测试消息
 * 用于开发测试阶段手动发送消息通知
 */
export const sendTestMessage = <ThrowOnError extends boolean = false>(options: Options<SendTestMessageData, ThrowOnError>) => {
    return (options.client ?? _heyApiClient).post<SendTestMessageResponses, unknown, ThrowOnError>({
        url: '/api/notifications/test/send',
        ...options,
        headers: {
            'Content-Type': 'application/json',
            ...options.headers
        }
    });
};

/**
 * 批量标记消息已读
 * 批量将多条消息标记为已读状态
 */
export const batchMarkAsRead = <ThrowOnError extends boolean = false>(options: Options<BatchMarkAsReadData, ThrowOnError>) => {
    return (options.client ?? _heyApiClient).post<BatchMarkAsReadResponses, unknown, ThrowOnError>({
        url: '/api/notifications/batch-read',
        ...options,
        headers: {
            'Content-Type': 'application/json',
            ...options.headers
        }
    });
};

/**
 * 获取用户消息列表
 * 分页获取指定用户的所有消息通知
 */
export const getMessages = <ThrowOnError extends boolean = false>(options: Options<GetMessagesData, ThrowOnError>) => {
    return (options.client ?? _heyApiClient).get<GetMessagesResponses, unknown, ThrowOnError>({
        url: '/api/notifications',
        ...options
    });
};

/**
 * 获取未读消息数量
 * 获取指定用户的未读消息总数
 */
export const getUnreadCount = <ThrowOnError extends boolean = false>(options: Options<GetUnreadCountData, ThrowOnError>) => {
    return (options.client ?? _heyApiClient).get<GetUnreadCountResponses, unknown, ThrowOnError>({
        url: '/api/notifications/unread-count',
        ...options
    });
};

/**
 * 获取各类型未读消息数量
 * 按消息类型分组统计指定用户的未读消息数量
 */
export const getUnreadCountByType = <ThrowOnError extends boolean = false>(options: Options<GetUnreadCountByTypeData, ThrowOnError>) => {
    return (options.client ?? _heyApiClient).get<GetUnreadCountByTypeResponses, unknown, ThrowOnError>({
        url: '/api/notifications/unread-count-by-type',
        ...options
    });
};

/**
 * 删除消息
 * 删除指定用户的某条消息
 */
export const deleteMessage = <ThrowOnError extends boolean = false>(options: Options<DeleteMessageData, ThrowOnError>) => {
    return (options.client ?? _heyApiClient).delete<DeleteMessageResponses, unknown, ThrowOnError>({
        url: '/api/notifications/{messageId}',
        ...options
    });
};